package com.pkk.components.exceptions;


import com.pkk.components.rpc.enums.CodeEnum;
import com.pkk.components.util.ExceptionUtil;
import lombok.Data;

/**
 * @description: 异常处理
 * @author: peikunkun
 * @create: 2018-08-13 14:14
 **/
@Data
public class BusinessException extends SysException {

  private static final long serialVersionUID = 5520881461291185272L;
  private CodeEnum codeEnum;

  /**
   * Constructs a new runtime exception with {@code null} as its detail message.  The cause is not initialized, and may
   * subsequently be initialized by a call to {@link #initCause}.
   */
  public BusinessException(CodeEnum codeEnum) {
    super(ExceptionUtil.getCodeAndMsg(codeEnum));
    this.codeEnum = codeEnum;
  }

  /**
   * Constructs a new runtime exception with the specified detail message and cause.  <p>Note that the detail message
   * associated with {@code cause} is <i>not</i> automatically incorporated in this runtime exception's detail message.
   *
   * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method).  (A <tt>null</tt>
   * value is permitted, and indicates that the cause is nonexistent or unknown.)
   * @since 1.4
   */
  public BusinessException(Throwable cause, CodeEnum codeEnum) {
    super(ExceptionUtil.getCodeAndMsg(codeEnum), cause);
    this.codeEnum = codeEnum;
  }


  public BusinessException(CodeEnum codeEnum, String message) {
    super(ExceptionUtil.getCodeCusMsg(codeEnum, message));
    this.codeEnum = codeEnum;
  }


}
